package com.nashuju.web.service.login;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

import org.durcframework.core.DurcException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nashuju.web.dao.sys.SysFunctionDao;
import com.nashuju.web.entity.sys.SysFunction;
import com.nashuju.web.entity.sys.SysOperate;
import com.nashuju.web.entity.sys.SysRes;
import com.nashuju.web.service.sw.STaskService;

/**
 * 添加操作点
 * @author hc.tang
 *
 */
@Service
public class AddOperateService {
    @Autowired
    private SysFunctionDao functionDao;

    /**
     * 添加操作权限 1. 添加功能
     * @param res 资源
     * @param operate 操作类型
     */
    public void add(SysRes res, SysOperate operate) {
        this.addFunction(res, operate);
    }


    // 添加系统功能,返回保存后的主键值
    private int addFunction(SysRes res, SysOperate operate) {
        SysFunction function = new SysFunction();

        function.setOperateCode(operate.getOperateCode());
        function.setSrId(res.getSrId());

        function.setFuncName(operate.getOperateName() + "(" + operate.getOperateCode() + ")");


        SysFunction storeFun = functionDao.get(function);

        if (storeFun != null) {
            throw new DurcException("添加失败 - [" + function.getFuncName() + "]记录已存在.");
        }

        functionDao.save(function);

        return function.getSfId();
    }
   
    
    
    

}
